package fragments;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.zengyan.myphonebook.R;
import com.nightonke.boommenu.BoomMenuButton;
import com.nightonke.boommenu.Types.BoomType;
import com.nightonke.boommenu.Types.ButtonType;
import com.nightonke.boommenu.Types.PlaceType;

import java.util.ArrayList;
import java.util.List;

import BD.SQLiteUtil;
import BD.mConfig;
import Bean.Member;
import butterknife.Bind;
import butterknife.ButterKnife;
import zengyan.adapter.CommonAdapter;
import zengyan.adapter.ViewHolder;

import static BD.mConfig.*;

/**
 * Created by zengyan on 2016/6/16.
 */
public class ListFragment extends Fragment {
    private String department;
    private RecyclerView mRecyclerView;
    private int id;
    private List<Member> allm=new ArrayList<Member>();
    private BaseQuickAdapter<Bean.Member> mQuickAdapter;





    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ButterKnife.bind(getActivity());
        return inflater.inflate(R.layout.fragment_demo, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
        Bundle bundle = getArguments();
        department= bundle.getString(KEY_DEPARTMENT);
        id=bundle.getInt(KEY_ID);
        intiData();
        mRecyclerView = (RecyclerView)getView().findViewById(R.id.rv_list);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        mRecyclerView.setAdapter(mQuickAdapter=new BaseQuickAdapter<Member>(getActivity(),R.layout.listview_layout,allm) {
            @Override
            protected void convert(BaseViewHolder baseViewHolder, Member member) {
                baseViewHolder.setText(R.id.membername_id,member.getMname());
                baseViewHolder.setText(R.id.memberposition_id,member.getMposition());
            }
        });
        mQuickAdapter.setOnRecyclerViewItemClickListener(new BaseQuickAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int i) {
                Member member=allm.get(i);
                ItemFragment item=ItemFragment.newInstance(member.getMlnum(),member.getMsnum());
                item.show(getChildFragmentManager(),"item");
            }
        });



    }

    private void intiData() {
        allm= SQLiteUtil.getAllMember(department,id);
    }
}
